// components/tabbar/tabbar.js
Component({
  properties: {
    activeIndex: {
      type: Number,
      value: 0
    }
  },

  data: {
    tabList: [
      {
        text: '时光长廊',
        iconPath: '/images/icon_home_new.png',
        selectedIconPath: '/images/icon_home_selected_new.png',
        pagePath: '/pages/index/index'
      },
      {
        text: '心情小偷',
        iconPath: '/images/icon_thief.png',
        selectedIconPath: '/images/icon_thief.png',
        pagePath: '/pages/thief/select/index'
      },
      {
        text: '个人中心',
        iconPath: '/images/icon_profile_new.png',
        selectedIconPath: '/images/icon_profile_selected_new.png',
        pagePath: '/pages/profile/profile'
      }
    ]
  },

  methods: {
    onTabChange(e) {
      const { index } = e.currentTarget.dataset;
      const tab = this.data.tabList[index];
      
      if (index === this.data.activeIndex) {
        // 如果点击的是当前页面，触发刷新事件
        this.triggerEvent('refresh');
      } else {
        // 切换tab
        wx.switchTab({
          url: tab.pagePath
        });
      }
    }
  }
});